package com.feidee.bigdata.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author:CHQ
 * @Date:2020/4/14 17:53
 * @Description
 */
@Service
public class PaymentService {


    public String ok() {
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return Thread.currentThread().getName() + " ok~ 哈哈哈哈";
    }

    //服务降级（客户端超过最大等待时间3s或此方法执行出错，都将进入兜底方法okHanel）
    @HystrixCommand(fallbackMethod = "errorHanel", commandProperties =
            {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})
    public String error() {
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return Thread.currentThread().getName() + " timeout";
    }

    public String errorHanel() {
        //Hystrix单独开辟了一个新线程维护兜底方法
        return Thread.currentThread().getName() + " 您好，服务繁忙，请稍后重试~";
    }

}
